UCI Adult Income Dataset - Exploratory and Descriptive Analysis

Author
Affiliation

Janviere Kakibibi

Junior Data Analyst

Published

June 25, 2025

In this notebook, we carry out an in-depth exploratory and descriptive analysis of the UCI Adult Income Dataset, a widely used dataset for income prediction tasks based on individual demographic and employment attributes.

This phase of analysis is essential for uncovering patterns, detecting potential biases, and gaining intuition about the dataset’s structure before applying any modelling procedures. We examine the distribution of key numerical and categorical variables, investigate relationships between demographic features and income levels, and use visualizations to summarize insights. Particular focus is placed on income disparities across age groups, geographical regions, races, and education-occupation combinations, helping lay a solid foundation for downstream modeling and policy-relevant interpretation.

We begin our analysis by importing the core Python libraries required for data handling, numerical computation, visualization, and directory management:

Code
# import libraries
import pandas as pd 
import numpy as np 
import os 
import plotly.express as px

1 Define and Create Directory Paths

To ensure reproducibility andorganized storage, we programmatically create directories if they don’t already exist for:

  • raw data
  • processed data
  • results
  • documentation

These directories will store intermediate and final outputs for reproducibility.

2 Loading the Cleaned Dataset

We load the cleaned version of the UCI Adult Income Dataset from the processed data directory into a Pandas DataFrame. The head(10) function shows the first ten records, giving a glimpse into the data columns such as age, workclass, education_num, etc. ::: {.panel-tabset} ## Output {.active}

Code
adult_data_filename = os.path.join(processed_dir, "adult_cleaned.csv")
adult_df = pd.read_csv(adult_data_filename)
adult_df.head(10)
Adult Income Dataset
age workclass fnlwgt education_num marital_status relationship race sex capital_gain capital_loss hours_per_week income education_level occupation-grouped native_region age_group
0 39 government 77516 13 single single white male 2174 0 40 <=50k tertiary white collor north america 36-45
1 50 self-employed 83311 13 married male spouse white male 0 0 13 <=50k tertiary white collor north america 46-60
2 38 private 215646 9 divorced or separated single white male 0 0 40 <=50k secondary graduate blue collor north america 36-45
3 53 private 234721 7 married male spouse black male 0 0 40 <=50k secondary blue collor north america 46-60
4 28 private 338409 13 married female spouse black female 0 0 40 <=50k tertiary white color central america 26-35
5 37 private 284582 14 married female spouse white female 0 0 40 <=50k tertiary white collor north america 36-45
6 49 private 160187 5 divorced or separated single black female 0 0 16 <=50k secondary service central america 46-60
7 52 self-employed 209642 9 married male spouse white male 0 0 45 >50k secondary graduate white collor north america 46-60
8 31 private 45781 14 single single white female 14084 0 50 >50k tertiary white color north america 26-35
9 42 private 159449 13 married male spouse white male 5178 0 40 >50k tertiary white collor north america 36-45

3 Code

Code
adult_data_filename = os.path.join(processed_dir, "adult_cleaned.csv")
adult_df = pd.read_csv(adult_data_filename)

::: ## Dataset Dimensions and Data Types

Here, we examine the structure of the dataset:

  • There are 32,513 entries and 16 variables.
  • The dataset includes both numerical (e.g., age, hours_per_week) and categorical variables (e.g., sex, education_level).

Understanding data types and null entries is essential before proceeding with analysis.

Code
summary_df = pd.DataFrame({
    'Column': adult_df.columns,
    'Data Type': adult_df.dtypes.values,
    'Missing Values': adult_df.isnull().sum().values
})
summary_df
Table 1: Overview of dataset columns, their data types, and the count of missing values in each column.
Column Data Type Missing Values
0 age int64 0
1 workclass object 0
2 fnlwgt int64 0
3 education_num int64 0
4 marital_status object 0
5 relationship object 0
6 race object 0
7 sex object 0
8 capital_gain int64 0
9 capital_loss int64 0
10 hours_per_week int64 0
11 income object 0
12 education_level object 0
13 occupation-grouped object 0
14 native_region object 0
15 age_group object 0

4 summary statistics: Numerical variables

Code
adult_df.describe()       #  sumaries the numerical data
Table 2: Summary statistics for numerical variables in the dataset, including count, mean, standard deviation, min, and quartile values.
age fnlwgt education_num capital_gain capital_loss hours_per_week
count 32533.000000 3.253300e+04 32533.000000 32533.000000 32533.000000 32533.000000
mean 38.587557 1.897849e+05 10.081640 1078.576338 87.378969 40.441306
std 13.637609 1.055601e+05 2.571689 7388.401928 403.125450 12.346494
min 17.000000 1.228500e+04 1.000000 0.000000 0.000000 1.000000
25% 28.000000 1.178330e+05 9.000000 0.000000 0.000000 40.000000
50% 37.000000 1.783560e+05 10.000000 0.000000 0.000000 40.000000
75% 48.000000 2.369930e+05 12.000000 0.000000 0.000000 45.000000
max 90.000000 1.484705e+06 16.000000 99999.000000 4356.000000 99.000000

This summary provides a snapshot of key distribution characteristics. We see that:

  • Age ranges from 17 to 90, with a mean of 38.6 years. It is slightly right-skewed (positively skewed). While the average age is approximately 38.6 years, an examination of the percentiles reveals that the majority of individuals are clustered in the younger to middle-age range, with fewer observations in the older age brackets. This skewed age distribution might suggest labor force participation is concentrated in specific age groups, which could reflect broader demographic or economic realities.
  • Capital gains/losses are highly skewed, with most values at 0 (the 75th percentile is 0). This indicates that a small number of individuals report very large gains or losses, especially evident in the capital gain variable which reaches up to $99,999. These variables act as proxies for wealth-related income that goes beyond regular wages or salaries. Individuals with non-zero values for capital gains or losses often represent a distinct socioeconomic subset of the population — typically more financially literate, or with access to investment assets. The stark inequality in their distributions mirrors real-world disparities in asset ownership and investment returns.
  • The dataset has individuals working anywhere from 1 to 99 hours per week, with a median of 40. This aligns with the standard full-time work week in many countries (8 hours per day for 5 working days). The mean is slightly above that at 40.4 hours, suggesting a mild right skew, with a small subset of individuals working significantly longer hours. The mode is also 40, further reinforcing the prevalence of full-time work. A non-trivial number of individuals report working very few hours, possibly due to part-time work, unemployment, or semi-retirement. On the other extreme, some report working more than 45 hours per week, which may indicate multiple jobs, weekend-work, self-employment, or informal labor, and could reflect socioeconomic necessity.

4.1 Summary Statistics: Categorical variables

workclass

Code
adult_df['workclass'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 3: Distribution of the workclass variable showing the proportion of each unique category within the dataset.
unique values proportion
0 private 0.696831
1 government 0.133710
2 self-employed 0.112378
3 unknown 0.056435
4 voluntary 0.000430
5 unemployed 0.000215

The private sector dominates, employing ~69.7% of the population. The government sector (13.4%) and self-employment (11.2%) also make up substantial portions of the workforce. A small fraction is labeled as “unknown” (5.6%), which may correspond to missing or ambiguous data entries. Tiny proportions are voluntary (0.04%) or unemployed (0.02%), possibly underreported or underrepresented in the sample.

marital_status

Code
adult_df['marital_status'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 4: Proportion of each category in the marital_status variable.
unique values proportion
0 married 0.460855
1 single 0.327760
2 divorced or separated 0.180863
3 widowed 0.030523

Married individuals make up the largest group (46.1%), followed by those who are single (32.8%) and divorced or separated (18.1%). Widowed individuals represent a small minority (~3.1%).

relationship

Code
adult_df['relationship'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 5: Distribution of the relationship variable by category proportions.
unique values proportion
0 male spouse 0.405342
1 single 0.360680
2 child 0.155627
3 female spouse 0.048197
4 extended relative 0.030154

The majority are labeled as “male spouse” (40.5%) or “single” (36.1%). Smaller categories include children (15.6%), female spouses (4.8%), and extended relatives (3.0%). The dominance of male spouse reflects the dataset’s gendered structure and may point to traditional family roles. The relative scarcity of “female spouse” roles suggests potential gender imbalances in how income-earning is reported within households.

race

Code
adult_df['race'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 6: Proportional breakdown of the race variable categories.
unique values proportion
0 white 0.854240
1 black 0.095964
2 asian or pacific islander 0.031906
3 american indian or eskimo 0.009560
4 other 0.008330

The dataset is overwhelmingly composed of White individuals (~85.4%). Other racial groups include Black (9.6%), Asian or Pacific Islander (3.2%), American Indian or Eskimo (1.0%), and Other (0.8%). The racial imbalance limits the generalizability of models trained on this data. Smaller racial groups may suffer from limited statistical power, affecting fairness and performance in predictive modeling.

sex

Code
adult_df['sex'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 7: Proportional distribution of the sex variable within the dataset.
unique values proportion
0 male 0.66929
1 female 0.33071

Males constitute 66.9% of the dataset, with females making up the remaining 33.1%. This male-skewed distribution could be due to sampling (e.g., primary earners in households), workforce participation patterns, or reporting biases.

education_level

Code
adult_df['education_level'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 8: Distribution of educational attainment levels (education_level) by proportion.
unique values proportion
0 secondary graduate 0.322565
1 tertiary 0.247810
2 unemployed 0.223773
3 secondary 0.093905
4 associate 0.075277
5 primary 0.035134
6 preschool 0.001537

Secondary-school graduates form the largest educational group (~32%), highlighting the central role of high school completion in the labor force. Tertiary education holders — those with university or equivalent degrees — account for nearly 25% of the population, representing a substantial segment with advanced qualifications. A notable 22.4% have attended some college without necessarily earning a degree, suggesting that partial post-secondary education is common, yet may not always translate into formal certification. The remaining 20% are distributed among those with only secondary education (9.4%), associate degrees (7.5%), primary school (3.5%), and a very small group with only preschool education (0.15%). It is ecident that the education distribution is skewed toward mid- to high-level education, with relatively few individuals having only basic schooling. This reflects a dataset that largely captures working-age adults in formal labor, which may underrepresent the least-educated populations.

native_region

Code
adult_df['native_region'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 9: Distribution of native_region categories by proportion.
unique values proportion
0 north america 0.923278
1 asia 0.020625
2 other 0.017890
3 central america 0.016107
4 europe 0.016015
5 south america 0.006086

The vast majority of individuals are from North America (~92.3%). Smaller proportions are from Central America, Asia, Europe, South America, and a generic Other category. The heavy concentration of North American individuals reflects the U.S. focus of the dataset.

age_group

Code
adult_df['age_group'].value_counts(normalize=True).rename_axis('unique values').reset_index(name='proportion')
Table 10: Proportional breakdown of the age_group categories in the dataset.
unique values proportion
0 26-35 0.261581
1 36-45 0.246058
2 46-60 0.224111
3 18-25 0.167553
4 61-75 0.064273
5 <18 0.029047
6 76+ 0.007377

The largest groups are 26–35 and 36–45, followed by 46–60. These three age groups represent about 73% of the dataset. Very few individuals are under 18 or above 75, consistent with the dataset’s focus on the working-age population.

5 Income Distribution

Given that income is the target variable, most of the analysis hereafter will be based on it. We first of all examine the income distribution in the dataset.

Code
fig = px.pie(adult_df_income, names='income' , values='total', title='Overall Income Distribution',color_discrete_sequence=['#0d2e03', '#56b33a'])
fig.update_layout(
    template='plotly_dark',  # Safe background styling
    paper_bgcolor='black'
)
fig.show()
fig.write_image(os.path.join(result_dir, 'income_distribution_pie_chart.jpg'))
fig.write_image(os.path.join(result_dir, 'income_distribution_pie_chart.png'))
fig.write_html(os.path.join(result_dir, 'income_distribution_pie_chart.html'))

This pie chart visualizes the overall income split: 76% of individuals earn ≤50K, while 24% earn >50K. This means that nearly 3 out of 4 individuals fall into the lower income bracket (<=50K). This shows that there is a significant imbalance.

5.1 Income by Age group

age_group income total_by_age percentage
0 18-25 <=50k 5337 97.908641
1 18-25 >50k 114 2.091359
2 26-35 <=50k 6919 81.304348
3 26-35 >50k 1591 18.695652
4 36-45 <=50k 5233 65.371643
5 36-45 >50k 2772 34.628357
6 46-60 <=50k 4480 61.445618
7 46-60 >50k 2811 38.554382
8 61-75 <=50k 1580 75.561932
9 61-75 >50k 511 24.438068
10 76+ <=50k 200 83.333333
11 76+ >50k 40 16.666667
12 <18 <=50k 945 100.000000
age_group income total_by_age percentage
0 18-25 <=50k 5337 97.908641
1 18-25 >50k 114 2.091359
2 26-35 <=50k 6919 81.304348
3 26-35 >50k 1591 18.695652
4 36-45 <=50k 5233 65.371643
5 36-45 >50k 2772 34.628357
6 46-60 <=50k 4480 61.445618
7 46-60 >50k 2811 38.554382
8 61-75 <=50k 1580 75.561932
9 61-75 >50k 511 24.438068
10 76+ <=50k 200 83.333333
11 76+ >50k 40 16.666667
12 <18 <=50k 945 100.000000
Code
fig = px.bar(
    adult_df_income_age,
    x = 'age_group',
    y = 'percentage',
    color = 'income',
    title = 'Income Distribution by Age Group (%)',
    barmode = 'group', 
    height = 500,
    color_discrete_sequence=px.colors.sequential.RdBu,
    text= 'percentage'
)
fig.update_traces(texttemplate='%{text:.2f}%', textposition='outside')
fig.update_layout(template="presentation", xaxis_title='Age Group', 
                  yaxis_title='Percentage of population', legend_title=dict(text='Income Level'),
                  paper_bgcolor = "rgba(0, 0, 0, 0)", plot_bgcolor = "rgba(0, 0, 0, 0)")
fig.show()

The bar chart visualizes the income distribution across age groups, using percentages within each group. There is an evident pattern in terms of income progression over the years with a gradual increase in terms of the number of people earning >50K starting from 0 amongst those aged 18 and below, peaking between 36 and 60 years, then declining after 60 years but not to zero.

All individuals under 18 earn <=50K, likely due to being students, minors, or ineligible for full-time employment. Extremely few young adults (2.1%) exceed 50K, as most are early in their careers, pursuing education, or in entry-level jobs. For the 26-35 age group, there’s a noticeable improvement — roughly 1 in 5 individuals in this group earn >50K, reflecting early career progression and accumulation of qualifications/experience. A substantial income increase is seen in the 36-45 age group: over a third now earn >50K. This is typically considered prime earning age where individuals settle into stable, higher-paying positions. Highest proportion of >50K earners is seen amongst individuals aged between 46 and 60— nearly 4 in 10. This reflects career maturity, peak seniority levels, and accumulated experience. There’s a drop-off in high incomes as many transition to retirement, part-time, or less demanding roles in the age group 61-75. Yet about 1 in 4 still earn >50K. Most in 76+ age group earn <=50K, likely due to retirement, pensions, or fixed incomes — but a small minority still earn higher incomes, possibly through continued work or investments.

5.2 Income by Native Region

Code
pip install -U kaleido
Requirement already satisfied: kaleido in c:\users\kepler\anaconda3\lib\site-packages (1.0.0)
Requirement already satisfied: choreographer>=1.0.5 in c:\users\kepler\anaconda3\lib\site-packages (from kaleido) (1.0.9)
Requirement already satisfied: logistro>=1.0.8 in c:\users\kepler\anaconda3\lib\site-packages (from kaleido) (1.1.0)
Requirement already satisfied: orjson>=3.10.15 in c:\users\kepler\anaconda3\lib\site-packages (from kaleido) (3.10.18)
Requirement already satisfied: packaging in c:\users\kepler\anaconda3\lib\site-packages (from kaleido) (23.2)
Requirement already satisfied: simplejson>=3.19.3 in c:\users\kepler\anaconda3\lib\site-packages (from choreographer>=1.0.5->kaleido) (3.20.1)
Note: you may need to restart the kernel to use updated packages.
Code
pip install -U plotly
Requirement already satisfied: plotly in c:\users\kepler\anaconda3\lib\site-packages (6.1.2)
Requirement already satisfied: narwhals>=1.15.1 in c:\users\kepler\anaconda3\lib\site-packages (from plotly) (1.43.1)
Requirement already satisfied: packaging in c:\users\kepler\anaconda3\lib\site-packages (from plotly) (23.2)
Note: you may need to restart the kernel to use updated packages.
Code
fig = px.bar(
    adult_df_income_reg,
    x = 'native_region',
    y = 'percentage',
    color = 'income',
    title = 'Income Distribution by Native Region (%)',
    barmode = 'group', 
    height = 600,
    width=1000,
    color_discrete_sequence=px.colors.sequential.RdBu,
    text= 'percentage'
)
fig.update_traces(texttemplate='%{text:.2f}%', textposition='outside')
fig.update_layout(template="presentation", xaxis_title='Native Region', yaxis_title='Percentage of population', legend_title=dict(text='Income Level'),
                  xaxis_title_standoff=50, paper_bgcolor = "rgba(0, 0, 0, 0)", plot_bgcolor = "rgba(0, 0, 0, 0)")
fig.show()

Asia (30.7%) and Europe (29.2%) have the highest proportions of high-income earners. This suggests these immigrant groups might be better integrated into high-paying professional roles, or may represent a more skilled migrant profile in the dataset. Central America (11.1%) and South America (12.1%) have the lowest proportions of >50K earners. With 24.2% of North Americans earning >50K, this serves as a middle-ground baseline. Interestingly, both Asian and European groups outperform the native-born population proportionally in high-income brackets. The ‘Other’ group sits around 25.1%, close to North America’s rate. This likely reflects a diverse mix of regions not explicitly listed.

5.3 Income by Race

Code
fig = px.bar(
    adult_df_income_race,
    x = 'race',
    y = 'percentage',
    color = 'income',
    title = 'Income Distribution by Race (%)',
    barmode = 'group', 
    height = 700,
    width=1000,
    color_discrete_sequence=px.colors.sequential.RdBu,
    text= 'percentage'
)
fig.update_traces(texttemplate='%{text:.2f}%', textposition='outside')
fig.update_layout(template="presentation", xaxis_title='Race', yaxis_title='Percentage of population', legend_title=dict(text='Income Level'),
                  xaxis_title_standoff=30, margin=dict(l=60, r=50, t=50, b=150), paper_bgcolor = "rgba(0, 0, 0, 0)", plot_bgcolor = "rgba(0, 0, 0, 0)")
fig.show()

Asian or Pacific Islander (26.6%) and White (25.6%) populations have the highest proportions of >50K earners. Asians/Pacific Islanders marginally outperform Whites, a pattern often attributed to occupational concentration in high-paying sectors like technology and medicine. On the other hand, American Indian or Eskimo (11.6%), Black (12.4%), and Other (9.2%) groups show significantly lower rates of high-income earners. These figures reflect long-standing economic disparities rooted in historical exclusion, occupational segregation, and systemic inequality.

The stark differences in high-income proportions:

  • Between Whites and Blacks: 25.6% vs 12.4% — slightly over double the proportion.
  • Between Asians and Others: 26.6% vs 9.2% — nearly triple.

These disparities are consistent with well-documented wage gaps and underrepresentation of marginalized groups in higher-paying roles.

6 Income by Education Level and Occupation Group

Code
final_file = os.path.join(processed_dir, 'adult_cleaned.csv')
adult_df.to_csv(final_file, index=False)

From the bar chart, we can pick out the largest groups per income-level. We see that secondary-school graduates working a blue collar job occupy the largest group in the dataset (3976). This reflects a common socio-economic profile: individuals with basic schooling in manual or technical trades predominantly earning lower incomes. The largest high-income group are tertiary-educated individuals in white collar roles. This highlights the strong earning advantage conferred by higher education and skilled jobs.

Some of the key patterns we can get from the dataset are:

  • Education matters, but isn’t deterministic

Tertiary education combined with white-collar work offers the highest income prospects. Yet a substantial number of tertiary-educated white-collar workers earn <=50K, likely early career, part-time, or structural pay gaps.

  • Blue-collar and service work predominantly pay <=50K, regardless of education.

Even some college education doesn’t guarantee high incomes in these sectors. Manual and service sector income is highly occupation-dependent (some skilled trades can break the 50K mark).

  • Some non-tertiary education groups do reach >50K

Secondary-school graduates in blue-collar and white-collar work have decent representation among >50K earners. This reflects upward mobility possible through skilled trades, tenure, or niche roles.

Code
print(adult_df.columns.tolist())
['age', 'workclass', 'fnlwgt', 'education_num', 'marital_status', 'relationship', 'race', 'sex', 'capital_gain', 'capital_loss', 'hours_per_week', 'income', 'education_level', 'occupation-grouped', 'native_region', 'age_group']